<?php

namespace App\Admin\Controllers\Data;

use App\Admin\Renderable\Data\SpellOptionData;
use App\Admin\Repositories\Data\ClickLearn;
use App\Models\Data\ClickLearn as ModelsClickLearn;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class ClickLearnController extends AdminController
{
    protected $title='内容';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ClickLearn(['spell_options']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('content','内容')->limit(50);
            $grid->column('translation','翻译')->limit(50);
            $grid->column('phonetic','音标')->limit(50);
            $grid->column('audio_url','音频地址')->limit(50);
            $grid->column('image_url','图片地址')->limit(50);
            $grid->column('sentence','单词例句')->limit(50);
            $grid->column('sentence_translation','例句翻译')->limit(50);
            $grid->column('type','类型')->display(function ($value){
                return ModelsClickLearn::$typeMap[$value];
            });
            $grid->column('sentence','单词例句')->limit(50);
            $grid->column('is_download','是否下载')->limit(50)->display(function ($value){
                if ($value===true){
                    return '<span style="color: #67C23A">是</span>';
                }
                return '<span style="color: #F56C6C">否</span>';
            });
            $grid->column('is_recite','是否背诵')->limit(50)->display(function ($value){
                if ($value===true){
                    return '<span style="color: #67C23A">是</span>';
                }
                return '<span style="color: #F56C6C">否</span>';
            });
            $grid->column('word_blanks','下划线')->limit(50);
            $grid->column('option','选项')->limit(50);
            $grid->column('option_order','选项排序')->limit(50);
            $grid->column('practice_translation','文件名称')->limit(50);

            $grid->column('spell_options','拼写变色')
                ->display(function ($value){
                    return count($value);
                })
                ->expand(SpellOptionData::make());
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchDelete();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }


}
